//
//  DetailMusicTableViewController.m
//  B项目
//
//  Created by lanou on 16/8/9.
//  Copyright © 2016年 Work. All rights reserved.
//

#import "DetailMusicTableViewController.h"
#import "DetaiMusicTableViewCell.h"
#import "PrefixHeader.pch"
#import "detailMusicModel.h"
#import "singerTableViewController.h"


@interface DetailMusicTableViewController ()

@property(nonatomic,strong)NSMutableArray *mArr;
@end

@implementation DetailMusicTableViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
   self.navigationItem.title = @"歌手详情";
    //模糊视图
    UIImage *backImg = [UIImage imageNamed:@"11471923,2560,1600.jpg"];
    UIImageView *imgV = [[UIImageView alloc]initWithImage:backImg];
    self.tableView.backgroundView = imgV;

    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:(UIBlurEffectStyleLight)];
    UIVisualEffectView *effectivew = [[UIVisualEffectView alloc]initWithEffect:blur];
    effectivew.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    [imgV addSubview:effectivew];

     [self.tableView registerNib:[UINib nibWithNibName:@"DetaiMusicTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];

    [self dataRequest];

    

}

//懒加载
- (NSMutableArray *)mArr
{
    if (!_mArr) {
        _mArr = [[NSMutableArray alloc]init];
    }
    return _mArr;
}


- (void)dataRequest
{
    [NetWorkRequestManager requestWithType:GET urlString:self.listUrl parDic:nil finish:^(NSData *data) {
        NSDictionary *rootDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        for (NSDictionary *dic in rootDict[@"artist"]) {
            detailMusicModel *model = [[detailMusicModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.mArr addObject:model];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
    } finishError:nil];
    

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.mArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DetaiMusicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    detailMusicModel *model = self.mArr[indexPath.row];


    [cell setDataWithModel:model];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    detailMusicModel *model = self.mArr[indexPath.row];
    singerTableViewController *singerVC = [[singerTableViewController alloc]init];
    singerVC.headImg = model.avatar_middle;
    singerVC.ting_uID = model.ting_uid;
    [self.navigationController pushViewController:singerVC animated:YES];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
